/*
 * DcSync.c
 *
 *  Created on: 2025年1月1日
 *      Author: chenlenan
 */
#include "DcSync.h"
int64 integral=0;
int64 toff=0;
int64 cycletime = 1000;

void ec_sync(int64 reftime, int64 cycletime , int64 *offsettime)
{
   int64 delta;
   /* set linux sync point 50us later than DC sync, just as example */
   delta = (reftime/1000 + 250) % cycletime;
   if(delta> (cycletime /2)) { delta= delta - cycletime; }
   if(delta>0){ integral++; }
   if(delta<0){ integral--; }
   *offsettime = -(delta / 2) - (integral /3);
}
